import vue from 'vue'
import Vuex from 'vuex'
import axios from "axios";
//使用vuex
vue.use(Vuex)

//创建actions
const actions={
    login(context,value){
      axios.get('http://localhost:8080/user/login?account='+value.account+'&password='+value.password).then(
          response=>{
              console.log(response.data)
          },
          error=>{
              console.log('请求出错了：'+error.message)
          }
      )
            // context.commit('login',value)
            // //登录成功
            // localStorage.setItem("isLoggedIn",true)
            // console.log(value)
    }
}

//创建mutations
const mutations={
    login(state,value){
            state.userId=value
    },
    toUrl(state,value){
        console.log('地址为：'+value)
        state.toUrl=value
    },
    addTabs(state,value){
        const tab={
            title:value.tabName,
            name: value.level,
            content:value.url
        }
            state.editableTabs.unshift(tab)
    },
    editTab(state,value){
        state.editableTabs=value
    },
}

//创建state
const state={
    userId:'zhangsan',
    userName:'张三',
    authTabs:[
        {
            tabName: '基础信息设置',
            level: '1-1',
            tabList: [
                {
                    level: '1-1-1',
                    tabName: '文件设置',
                    tabList: [
                        {
                            level: '1-1-1-1',
                            tabName: '图片上传',
                            url: '/home/imgUpdate'
                        },
                        {
                            level: '1-1-1-2',
                            tabName: '文件上传',
                            url: '/home/'
                        }
                    ]
                },
                {
                    level:'1-2-1',
                    tabName: '基础设置',
                    tabList:[
                        {
                            level: '1-2-1-1',
                            tabName: '图片上传',
                            url: '/home/imgUpdate'
                        },
                        {
                            level: '1-2-1-2',
                            tabName: '文件上传',
                            url: '/'
                        }
                    ]
                }
            ]
        }
    ],
    toUrl:'/',
    editableTabs: [],
}

//创建store并暴露
export default new Vuex.Store({
    actions,
    mutations,
    state
})
